package com.sdy.dao.mysql;

import com.sdy.po.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from s_user where username=#{username} and password=#{password}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "companyId",property = "companyId"),
            @Result(column="companyId",property="company",one=@One(select="com.sdy.dao.mysql.CompanyMapper.selectCompanyNameById",fetchType = FetchType.EAGER)),
            @Result(column = "id", property = "authority", one = @One(select = "com.sdy.dao.mysql.AuthorityMapper.selectAuthorityByUserId", fetchType = FetchType.EAGER))
    })
    User doLogin(@Param("username") String username, @Param("password") String password);

    @Insert("insert into s_user(username, password, name) values(#{username}, #{password}, #{name})")
    Integer doRegist(@Param("username") String username, @Param("password") String password, @Param("name") String name);

    @Select("select name from s_user where id = #{id}")
    String getNameById(@Param("id") Integer id);

    @Select("select id,companyId from s_user where companyId = '1'")
    List<User> ListManagerNameAndCompanyId();

    @Select("select id,companyId from s_user")
    List<User> ListAllNameAndCompanyId();

    @Select("select id,companyId from s_user where companyId != '1'")
    List<User> ListCustomerNameAndCompanyId();
}
